package com.xiaochen.baidu.config;

import com.xiaochen.baidu.service.IMoiuLoginService;
import com.xiaochen.baidu.service.IMoiuParseService;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;

import java.io.IOException;

/**
 * @author xc
 * @date 2025/10/09/13:18
 * @desc retrofit2配置类
 */
@Slf4j
@Configuration
public class Retrofit2Config {
    private static final String BASE_URL1 = "https://moids.moiu.cn";
    private static final String BASE_URL2 = "https://api.moiu.cn";

    @Bean
    public Retrofit retrofit1(){
        OkHttpClient client = new OkHttpClient.Builder()
                .followRedirects(false)  // 禁用重定向
                .followSslRedirects(false)  // 禁用SSL重定向
                .build();

        return new Retrofit.Builder()
                .baseUrl(BASE_URL1)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
    }
    @Bean
    public Retrofit retrofit2(){
        OkHttpClient client = new OkHttpClient.Builder()
                .followRedirects(false)  // 禁用重定向
                .followSslRedirects(false)  // 禁用SSL重定向
                .build();

        return new Retrofit.Builder()
                .baseUrl(BASE_URL2)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
    }
    
    
    @Bean
    public IMoiuLoginService moiuService(Retrofit retrofit1){
        return retrofit1.create(IMoiuLoginService.class);
    }
    
    @Bean
    public IMoiuParseService moiuParseService(Retrofit retrofit2){
        return retrofit2.create(IMoiuParseService.class);
    }
    
}
